#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <sys/ioctl.h>


#define BUFF_LEN 100

#include "mychar.h"


int main(int argc, char *argv[]){
	int fd = -1;
	char buff[BUFF_LEN] = "";
	int maxLen = 0;
	int curLen = 0;
	fd_set set;
	int ret = 0;

	if(argc < 2){
		printf("too few arguments\n");
		return 1;
	}

	fd = open(argv[1], O_RDWR);

	if(fd < 0){
		printf("open failed : %s \n", argv[1]);
		return 2;
	}

	FD_ZERO(&set);
	FD_SET(fd, &set);

	while(1){
		
		if(ret = select(fd + 1, &set, NULL, NULL, NULL) < 0){
			printf("select  error... \n");
		}
		if(ret < 0){
			
			//错误：中断信号
			if(errno == EINTR){
				continue;
			}else{
				printf("select error \n");
				break;
			}
		}
		if(FD_ISSET(fd, &set)){
			ret = read(fd, buff, BUFF_LEN);
			printf("read Buff is %s\n", buff);
		}
	}

	close(fd);
	return 0;
}
